const data = {
  'id': 17574,
  'surname': '张',
  'name': '噢',
  'fq_id': 0,
  'mq_id': 0,
  'qz_id': 18672,
  'sex': 1,
  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
  'is_spouse': 1,
  'card_zi': null,
  'shi': 11,
  'is_del': 1,
  'level': 1,
  'fq_name': '',
  'mq_name': '',
  'qz_name': '李秀清',
  'gxname': '高祖父',
  'spouses': [
    18672,
  ],
  'children': [
    {
      'id': 17549,
      'surname': '张',
      'name': '丽',
      'fq_id': 17574,
      'mq_id': 18672,
      'qz_id': 17573,
      'sex': 1,
      'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
      'is_spouse': 1,
      'card_zi': null,
      'shi': 12,
      'is_del': 1,
      'level': 1,
      'fq_name': '张噢',
      'mq_name': '李秀清',
      'qz_name': '江欣茹',
      'gxname': '曾祖父',
      'spouses': [
        17573,
      ],
      'children': [
        {
          'id': 17548,
          'surname': '张',
          'name': '张',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 18036,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 3,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '柳淑娟',
          'gxname': '爷爷',
          'spouses': [
            17569,
            18036,
          ],
          'children': [
            {
              'id': 4557,
              'surname': '张',
              'name': '海',
              'fq_id': 17548,
              'mq_id': 17569,
              'qz_id': 4559,
              'sex': 1,
              'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
              'is_spouse': 1,
              'card_zi': null,
              'shi': 14,
              'is_del': 1,
              'level': 1,
              'fq_name': '张张',
              'mq_name': '任紫',
              'qz_name': '杨淑',
              'gxname': '父亲',
              'spouses': [
                4559,
              ],
              'children': [
                {
                  'id': 4530,
                  'surname': '张',
                  'name': '顺',
                  'fq_id': 4557,
                  'mq_id': 4559,
                  'qz_id': 0,
                  'sex': 1,
                  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/481feda7ff8ab2aa0b39adbb8969a83a.png',
                  'is_spouse': 1,
                  'card_zi': null,
                  'shi': 15,
                  'is_del': 1,
                  'level': 30,
                  'fq_name': '张海',
                  'mq_name': '杨淑',
                  'qz_name': '',
                  'gxname': '本人',
                  'spouses': [],
                  'children': [
                    {
                      'id': 18343,
                      'surname': '李',
                      'name': '还是很',
                      'fq_id': 4530,
                      'mq_id': 0,
                      'qz_id': 0,
                      'sex': 1,
                      'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/e8b9789ded3d032bdea2c413ad7d4b7d.png',
                      'is_spouse': 1,
                      'card_zi': null,
                      'shi': 16,
                      'is_del': 1,
                      'level': 3,
                      'fq_name': '张顺',
                      'mq_name': '',
                      'qz_name': '',
                      'gxname': '儿子',
                      'spouses': [],
                      'children': [
                        {
                          'id': 18353,
                          'surname': '李',
                          'name': '高',
                          'fq_id': 18343,
                          'mq_id': 0,
                          'qz_id': 0,
                          'sex': 1,
                          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/e8b9789ded3d032bdea2c413ad7d4b7d.png',
                          'is_spouse': 1,
                          'card_zi': null,
                          'shi': 17,
                          'is_del': 1,
                          'level': 13,
                          'fq_name': '李还是很',
                          'mq_name': '',
                          'qz_name': '',
                          'gxname': '孙子',
                          'spouses': [],
                          'children': [
                            {
                              'id': 18355,
                              'surname': '李',
                              'name': '高规格',
                              'fq_id': 18353,
                              'mq_id': 0,
                              'qz_id': 0,
                              'sex': 1,
                              'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/e8b9789ded3d032bdea2c413ad7d4b7d.png',
                              'is_spouse': 1,
                              'card_zi': null,
                              'shi': 18,
                              'is_del': 1,
                              'level': 15,
                              'fq_name': '李高',
                              'mq_name': '',
                              'qz_name': '',
                              'gxname': '曾孙',
                              'spouses': [],
                              'children': [
                                {
                                  'id': 18361,
                                  'surname': '李',
                                  'name': '湖',
                                  'fq_id': 18355,
                                  'mq_id': 0,
                                  'qz_id': 0,
                                  'sex': 0,
                                  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7264428c6e6e539bf25f9143b1570f6f.png',
                                  'is_spouse': 1,
                                  'card_zi': null,
                                  'shi': 19,
                                  'is_del': 1,
                                  'level': 21,
                                  'fq_name': '李高规格',
                                  'mq_name': '',
                                  'qz_name': '',
                                  'gxname': '族亲',
                                  'spouses': [],
                                  'children': [],
                                },
                              ],
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
                {
                  'id': 4748,
                  'surname': '张',
                  'name': '淑',
                  'fq_id': 4557,
                  'mq_id': 4559,
                  'qz_id': 4750,
                  'sex': 0,
                  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/ff767d55f6f78728d6cf27e385d1c2c9.png',
                  'is_spouse': 1,
                  'card_zi': null,
                  'shi': 15,
                  'is_del': 1,
                  'level': 36,
                  'fq_name': '张海',
                  'mq_name': '杨淑',
                  'qz_name': '李秦',
                  'gxname': '妹',
                  'spouses': [
                    4750,
                  ],
                  'children': [],
                },
              ],
            },
          ],
        },
        {
          'id': 17727,
          'surname': '张',
          'name': '明',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 18367,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/481feda7ff8ab2aa0b39adbb8969a83a.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 1,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '关雕花',
          'gxname': '伯祖父',
          'spouses': [
            18367,
          ],
          'children': [
            {
              'id': 18378,
              'surname': '张',
              'name': '湖',
              'fq_id': 17727,
              'mq_id': 18367,
              'qz_id': 18379,
              'sex': 1,
              'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/e8b9789ded3d032bdea2c413ad7d4b7d.png',
              'is_spouse': 1,
              'card_zi': null,
              'shi': 14,
              'is_del': 1,
              'level': 21,
              'fq_name': '张明',
              'mq_name': '关雕花',
              'qz_name': '金福星',
              'gxname': '堂叔父',
              'spouses': [
                18379,
              ],
              'children': [
                {
                  'id': 22639,
                  'surname': '林',
                  'name': '江',
                  'fq_id': 18378,
                  'mq_id': 18379,
                  'qz_id': 0,
                  'sex': 1,
                  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
                  'is_spouse': 1,
                  'card_zi': null,
                  'shi': 15,
                  'is_del': 1,
                  'level': 1,
                  'fq_name': '张湖',
                  'mq_name': '金福星',
                  'qz_name': '',
                  'gxname': '从兄',
                  'spouses': [],
                  'children': [
                    {
                      'id': 22640,
                      'surname': '林',
                      'name': '张',
                      'fq_id': 22639,
                      'mq_id': 281907,
                      'qz_id': 229929,
                      'sex': 1,
                      'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
                      'is_spouse': 1,
                      'card_zi': null,
                      'shi': 16,
                      'is_del': 1,
                      'level': 1,
                      'fq_name': '林江',
                      'mq_name': '江月',
                      'qz_name': '这好',
                      'gxname': '族亲',
                      'spouses': [],
                      'children': [
                        {
                          'id': 22641,
                          'surname': '林',
                          'name': '中',
                          'fq_id': 22640,
                          'mq_id': 0,
                          'qz_id': 0,
                          'sex': 1,
                          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
                          'is_spouse': 1,
                          'card_zi': null,
                          'shi': 17,
                          'is_del': 1,
                          'level': 1,
                          'fq_name': '林张',
                          'mq_name': '',
                          'qz_name': '',
                          'gxname': '再从侄孙',
                          'spouses': [],
                          'children': [
                            {
                              'id': 22642,
                              'surname': '林',
                              'name': '你',
                              'fq_id': 22641,
                              'mq_id': 0,
                              'qz_id': 22643,
                              'sex': 1,
                              'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
                              'is_spouse': 1,
                              'card_zi': null,
                              'shi': 18,
                              'is_del': 1,
                              'level': 1,
                              'fq_name': '林中',
                              'mq_name': '',
                              'qz_name': '秦葭',
                              'gxname': '族亲',
                              'spouses': [
                                22643,
                              ],
                              'children': [
                                {
                                  'id': 22644,
                                  'surname': '林',
                                  'name': '柔',
                                  'fq_id': 22642,
                                  'mq_id': 22643,
                                  'qz_id': 22645,
                                  'sex': 2,
                                  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241224/cee37d19330eb5bafa79987867240388.jpg',
                                  'is_spouse': 1,
                                  'card_zi': null,
                                  'shi': 19,
                                  'is_del': 1,
                                  'level': 8,
                                  'fq_name': '林你',
                                  'mq_name': '秦葭',
                                  'qz_name': '韩光年',
                                  'gxname': '族亲',
                                  'spouses': [
                                    22645,
                                  ],
                                  'children': [],
                                },
                              ],
                            },
                          ],
                        },
                      ],
                    },
                    {
                      'id': 212572,
                      'surname': '赵',
                      'name': '坡',
                      'fq_id': 22639,
                      'mq_id': 0,
                      'qz_id': 284862,
                      'sex': 1,
                      'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
                      'is_spouse': 1,
                      'card_zi': null,
                      'shi': 16,
                      'is_del': 1,
                      'level': 1,
                      'fq_name': '林江',
                      'mq_name': '',
                      'qz_name': '张丽然',
                      'gxname': '从侄',
                      'spouses': [
                        277637,
                        284862,
                      ],
                      'children': [
                        {
                          'id': 212574,
                          'surname': '赵',
                          'name': '建宇',
                          'fq_id': 212572,
                          'mq_id': 277637,
                          'qz_id': 0,
                          'sex': 1,
                          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/7894c20e5e973b2c4f4edf93178903d0.png',
                          'is_spouse': 1,
                          'card_zi': null,
                          'shi': 17,
                          'is_del': 1,
                          'level': 1,
                          'fq_name': '赵坡',
                          'mq_name': '江萍',
                          'qz_name': '',
                          'gxname': '再从侄孙',
                          'spouses': [],
                          'children': [
                            {
                              'id': 212575,
                              'surname': '赵',
                              'name': '俊鹏',
                              'fq_id': 212574,
                              'mq_id': 0,
                              'qz_id': 212576,
                              'sex': 1,
                              'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241028/5480d5e383dd521b43e33e08ee5859b2.png',
                              'is_spouse': 1,
                              'card_zi': null,
                              'shi': 18,
                              'is_del': 1,
                              'level': 3,
                              'fq_name': '赵建宇',
                              'mq_name': '',
                              'qz_name': '李晶晶',
                              'gxname': '族亲',
                              'spouses': [
                                212576,
                              ],
                              'children': [
                                {
                                  'id': 212577,
                                  'surname': '赵',
                                  'name': '坤',
                                  'fq_id': 212575,
                                  'mq_id': 212576,
                                  'qz_id': 0,
                                  'sex': 1,
                                  'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/e8b9789ded3d032bdea2c413ad7d4b7d.png',
                                  'is_spouse': 1,
                                  'card_zi': null,
                                  'shi': 19,
                                  'is_del': 1,
                                  'level': 1,
                                  'fq_name': '赵俊鹏',
                                  'mq_name': '李晶晶',
                                  'qz_name': '',
                                  'gxname': '族亲',
                                  'spouses': [],
                                  'children': [],
                                },
                              ],
                            },
                          ],
                        },
                      ],
                    },
                  ],
                },
              ],
            },
            {
              'id': 18391,
              'surname': '张',
              'name': '家',
              'fq_id': 17727,
              'mq_id': 18367,
              'qz_id': 0,
              'sex': 0,
              'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/4231f344ccce2641ddc58d6d7bee6b97.png',
              'is_spouse': 1,
              'card_zi': null,
              'shi': 14,
              'is_del': 1,
              'level': 19,
              'fq_name': '张明',
              'mq_name': '关雕花',
              'qz_name': '',
              'gxname': '堂姑',
              'spouses': [],
              'children': [],
            },
          ],
        },
        {
          'id': 17728,
          'surname': '张',
          'name': '柔',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 17729,
          'sex': 0,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/45263bd5dce71a320d0893e3f79e851a.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 4,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '贾仁泽',
          'gxname': '姑祖母',
          'spouses': [
            17729,
          ],
          'children': [],
        },
        {
          'id': 228486,
          'surname': '哥',
          'name': '树222',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 0,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241028/5480d5e383dd521b43e33e08ee5859b2.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 22,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '',
          'gxname': '叔祖父',
          'spouses': [],
          'children': [],
        },
        {
          'id': 228605,
          'surname': '哥',
          'name': '树222',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 0,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241028/5480d5e383dd521b43e33e08ee5859b2.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 22,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '',
          'gxname': '叔祖父',
          'spouses': [],
          'children': [],
        },
        {
          'id': 228647,
          'surname': '哥',
          'name': '树222',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 0,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241028/5480d5e383dd521b43e33e08ee5859b2.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 22,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '',
          'gxname': '叔祖父',
          'spouses': [],
          'children': [],
        },
        {
          'id': 228771,
          'surname': '哥',
          'name': '树222',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 0,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241028/5480d5e383dd521b43e33e08ee5859b2.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 22,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '',
          'gxname': '叔祖父',
          'spouses': [],
          'children': [],
        },
        {
          'id': 228815,
          'surname': '哥',
          'name': '树222',
          'fq_id': 17549,
          'mq_id': 17573,
          'qz_id': 0,
          'sex': 1,
          'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241028/5480d5e383dd521b43e33e08ee5859b2.png',
          'is_spouse': 1,
          'card_zi': null,
          'shi': 13,
          'is_del': 1,
          'level': 22,
          'fq_name': '张丽',
          'mq_name': '江欣茹',
          'qz_name': '',
          'gxname': '叔祖父',
          'spouses': [],
          'children': [],
        },
      ],
    },
    {
      'id': 18673,
      'surname': '张',
      'name': '月',
      'fq_id': 17574,
      'mq_id': 18672,
      'qz_id': 22547,
      'sex': 0,
      'head': 'https://mznc-oss.oss-cn-beijing.aliyuncs.com/uploads/20241029/45263bd5dce71a320d0893e3f79e851a.png',
      'is_spouse': 1,
      'card_zi': null,
      'shi': 12,
      'is_del': 1,
      'level': 2,
      'fq_name': '张噢',
      'mq_name': '李秀清',
      'qz_name': '李志平',
      'gxname': '曾祖姑母',
      'spouses': [
        22547,
      ],
    },
  ],
};

// 计算每个节点的层级
function calculateLevels(node, level = 1) {
  node.calculatedLevel = level;
  if (node.children) {
    node.children.forEach(child => calculateLevels(child, level + 1));
  }
}

// 收集所有层级为5k+1的节点
const roots = [];

function collectRoots(node) {
  if ((node.calculatedLevel - 1) % 5 === 0) {
    roots.push(node);
  }
  if (node.children) {
    node.children.forEach(collectRoots);
  }
}

// 生成子树，最多maxLevel层
function generateSubtree(node, maxLevel) {
  const subtree = { ...node };
  subtree.children = [];
  if (maxLevel <= 0 || !node.children) {
    return subtree;
  }
  subtree.children = node.children.map(child => generateSubtree(child, maxLevel - 1));
  return subtree;
}

// 处理数据
calculateLevels(data);
collectRoots(data);
const result = roots.map(root => generateSubtree(root, 4));

// 输出结果
console.log(JSON.stringify(result, null, 2));